package io.gitee.hejiang.action;

import java.util.Map;
import java.util.ServiceLoader;

public interface SwaggerSqlActionProvider {
	SwaggerSqlAction createAction(Map<String, Object> config);

	static ServiceLoader<SwaggerSqlActionProvider> _loader = ServiceLoader
			.load(SwaggerSqlActionProvider.class);

	static SwaggerSqlAction build(Map<String, Object> config) throws Exception {
		for (SwaggerSqlActionProvider provider : _loader) {
			SwaggerSqlAction action = provider.createAction(config);
			if (action != null) {
				return action;
			}
		}

		throw new Exception(
				"Fail to create action from config: " + config.toString());
	}
}
